<?php
namespace app\index\controller;
use think\Cookie;

class IndexAjax extends Common
{
    public function docking(){
        if(request()->port()){
            $domain = input('domain');
            $qq = input('qq');
            $type = input('type');
            $uid = Cookie::get("smalls_userId");
            if(strlen($qq) < 5 || strlen($qq) > 11){
                $this->assign("sweetAlert", sweetAlert("温馨提示", "QQ号码不正确！", "2",'REFERER'));
            }if(strpos($domain,'.') == false && strpos($domain,'www.') == true){
                $this->assign("sweetAlert", sweetAlert("温馨提示", "域名不正确！", "2",'REFERER'));
            }elseif($type==0){
                $this->assign("sweetAlert", sweetAlert("温馨提示", "请选择授权模式！", "2",'REFERER'));
            }elseif($this->pdo->find('select uid from smalls_auth where domain=:domain where limit 1', array(':domain' => $domain))){
                $this->assign("sweetAlert", sweetAlert("温馨提示", "此域名已存在，有问题联系客服！", "3",'REFERER'));
            }elseif($this->pdo->execute("INSERT INTO `smalls_auth` (`domain`, `domain2`, `type`, `status`, `uid`, `qq`, `time`) VALUES (:domain, :domain2, :type, '1', :uid, :qq, NOW())", array(':domain' => $domain, ':domain2' => 'www.'.$domain, ':type' => $type, ':uid' => $uid, ':qq' => $qq))){
                $this->assign('sweetAlert',sweetAlert('添加成功','现在可以开始对接接口','1',url('index/docking')));
            }
            exit($this->fetch('common/sweetalert'));
        }
    }
}